package exercise;

import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.util.Properties;

public class ReflectExampleDemo {

    public static void main(String[] args) throws Exception {
        Properties properties = new Properties();
        InputStream in = ReflectExampleDemo.class.getClassLoader().getResourceAsStream("person.properties");
        properties.load(in);

        String className = properties.getProperty("className");
        String name = properties.getProperty("name");
        String gender = properties.getProperty("gender");
        int age = Integer.parseInt(properties.getProperty("age"));

        Class clazz = Class.forName(className);
        Constructor constructor = clazz.getDeclaredConstructor(String.class,String.class,int.class);
        Person p = (Person) constructor.newInstance(name,gender,age);
        System.out.println(p);
    }
}
